/*
 * 软件著作权：北京康兰尚德数据科技有限公司
 * 项目名称：康兰数据购物中心分析平台
 *
 * NAME : PraiseDaoImpl.java
 *
 * PURPOSE : 网店数据库访问
 *
 * AUTHOR : EEDATA/ywb
 *
 *
 * 创建日期: 2013-12-06
 * HISTORY：
 * 变更日期 
 */
package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import pojo.EcpPpPraise;
import util.HibernateUtils;

/**
 * 用户赞数据访问层
 * 
 * @author ywb
 */

public class PraiseDaoImpl {

	/**
	 * 用户赞特定新品
	 */
	public boolean insertnewbrandPraise(EcpPpPraise praise) {// 二十一、applaudNewProduct接口
		Session session = null;
		Transaction ts = null;
		boolean row = true;
		try {
			session = HibernateUtils.getSession();
			ts = session.beginTransaction();

			session.persist(praise);

			ts.commit();

		} catch (Exception e) {
			e.printStackTrace();
			row = false;
			ts.rollback();
		} finally {
			HibernateUtils.closeSession(session);
		}

		return row;

	}

	@SuppressWarnings("unchecked")
	public boolean checkPraise(EcpPpPraise praise) {// 三十、isApplaudNewProduct
		Session session = null;
		Transaction ts = null;
		boolean row = false;
		try {
			session = HibernateUtils.getSession();
			ts = session.beginTransaction();

			Query query = session
					.createQuery("from EcpPpPraise where userid=? and braotherid=?");
			query.setParameter(0, praise.getUserid());
			query.setParameter(1, praise.getBraotherid());

			List<EcpPpPraise> list = query.list();

			if (list.size() > 0)
				row = true;

			ts.commit();

		} catch (Exception e) {
			e.printStackTrace();
			ts.rollback();
		} finally {
			HibernateUtils.closeSession(session);
		}

		return row;

	}
}
